<?php

namespace YouBaoLian\Application\Response;

use YouBaoLian\Http\Response;

class VehicleQuoteResponse extends Response
{

    /**
     * 保司ID
     * @var  $supplierId
     */
    private $supplierId;

    /**
     * 重复投保标志
     * @var  $reInsureFlg
     */
    private $reInsureFlg;

    /**
     * 重复投保信息
     * @var  $repeatInsureInfo
     */
    private $repeatInsureInfo;

    private $priceItemId;

    private $payNeedCheckCode = 0;

    private $needSignEleFlag = 0;

    private $needCancelOrder = 0;

    private $biBeginDate;

    private $biEndDate;

    private $biDiscount;

    private $biPremium;

    private $biSlipNo;

    private $carShipTax;

    private $fcPremium;

    private $ciBeginDate;

    private $ciEndDate;

    private $ciDiscount;

    private $ciPremium;

    private $ciSlipNo;

    private $totalPrice;

    private $coverageList;

    private $vehicleModel;

    private $status;

    /**
     * 业务数据
     * @var  $data
     */
    private $data;


    public function build(): Response
    {
        parent::build();

        $this->resultCode = $this->getBizContent('resultCode', 0);
        $this->supplierId = $this->getBizContent('supplierId');
        $this->reInsureFlg = $this->getBizContent('reInsureFlg');
        $this->repeatInsureInfo = $this->getBizContent('repeatInsureInfo');
        $this->data = $this->getBizContent('data')[0] ?? '';
        $this->status = $this->data['status'] ?? 0;

        if (!$this->reInsureFlg or $this->status == 2) {
            $this->priceItemId = $this->data['priceItemId'] ?? $this->data['priceId'] ?? '';
            $this->biBeginDate = $this->data['biBeginDate'] ?? '';
            $this->biEndDate = $this->data['biEndDate'] ?? '';
            $this->biDiscount = $this->data['biDiscount'] ?? '0';
            $this->biPremium = $this->data['biPremium'] ?? '0';
            $this->biSlipNo = $this->data['biSlipNo'] ?? '';
            $this->carShipTax = $this->data['carShipTax'] ?? '0';
            $this->fcPremium = $this->data['fcPremium'] ?? '0';
            $this->ciBeginDate = $this->data['ciBeginDate'] ?? '';
            $this->ciEndDate = $this->data['ciEndDate'] ?? '';
            $this->ciDiscount = $this->data['ciDiscount'] ?? '0';
            $this->ciPremium = $this->data['ciPremium'] ?? '0';
            $this->ciSlipNo = $this->data['ciSlipNo'] ?? '';
            $this->totalPrice = $this->data['totalPrice'] ?? '0';
            $this->coverageList = $this->data['coverageList'] ?? [];
            $this->vehicleModel = $this->data['vehicleModel'] ?? [];

            $this->querySuccess();

        } else {
            $this->repeatInsureInfo = $this->getBizContent('repeatInsureInfo', '');
            if (!$this->repeatInsureInfo) {
                $this->repeatInsureInfo = $this->getBizContent('repeatTipMessage', '');
            }

            if ($this->repeatInsureInfo and is_array($this->repeatInsureInfo)) {
                $this->repeatInsureInfo = json_encode($this->repeatInsureInfo);
            }

            $this->setError($this->message);
        }

        return $this;
    }

    private function querySuccess()
    {
        if ($this->message and $this->status != 2) {

            $this->setError($this->message);
            return;
        }
        switch ($this->status) {
            case 0:
                $this->setError('询价失败');
                break;
            case 9:
                $this->setError($this->message);
                break;
            case 3:
                $this->setError('重复投保');
                break;
        }
    }

    /**
     * @return mixed
     */
    public function getSupplierId()
    {
        return $this->supplierId;
    }

    /**
     * @return mixed
     */
    public function getReInsureFlg()
    {
        return $this->reInsureFlg;
    }

    /**
     * @return mixed
     */
    public function getRepeatInsureInfo()
    {
        return $this->repeatInsureInfo;
    }

    /**
     * @return mixed
     */
    public function getData()
    {
        return $this->data;
    }

    /**
     * @return int
     */
    public function getPayNeedCheckCode(): int
    {
        return $this->payNeedCheckCode;
    }

    /**
     * @return int
     */
    public function getNeedSignEleFlag(): int
    {
        return $this->needSignEleFlag;
    }

    /**
     * @return int
     */
    public function getNeedCancelOrder(): int
    {
        return $this->needCancelOrder;
    }

    /**
     * @return mixed
     */
    public function getPriceItemId()
    {
        return $this->priceItemId;
    }

    /**
     * @return mixed
     */
    public function getBiBeginDate()
    {
        return $this->biBeginDate;
    }

    /**
     * @return mixed
     */
    public function getBiEndDate()
    {
        return $this->biEndDate;
    }

    /**
     * @return mixed
     */
    public function getBiDiscount()
    {
        return $this->biDiscount;
    }

    /**
     * @return mixed
     */
    public function getBiPremium()
    {
        return $this->biPremium;
    }

    /**
     * @return mixed
     */
    public function getBiSlipNo()
    {
        return $this->biSlipNo;
    }

    /**
     * @return mixed
     */
    public function getCarShipTax()
    {
        return $this->carShipTax;
    }

    /**
     * @return mixed
     */
    public function getFcPremium()
    {
        return $this->fcPremium;
    }

    /**
     * @return mixed
     */
    public function getCiBeginDate()
    {
        return $this->ciBeginDate;
    }

    /**
     * @return mixed
     */
    public function getCiEndDate()
    {
        return $this->ciEndDate;
    }

    /**
     * @return mixed
     */
    public function getCiDiscount()
    {
        return $this->ciDiscount;
    }

    /**
     * @return mixed
     */
    public function getCiPremium()
    {
        return $this->ciPremium;
    }

    /**
     * @return mixed
     */
    public function getCiSlipNo()
    {
        return $this->ciSlipNo;
    }

    /**
     * @return mixed
     */
    public function getTotalPrice()
    {
        return $this->totalPrice;
    }

    /**
     * @return mixed
     */
    public function getCoverageList()
    {
        return $this->coverageList;
    }

    /**
     * @return mixed
     */
    public function getVehicleModel()
    {
        return $this->vehicleModel;
    }

    /**
     * @return mixed
     */
    public function getStatus()
    {
        return $this->status;
    }


}
